<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="eidt">
    <div class="layui-form-item" >
        <label class="layui-form-label required">分类ID</label>
        <div class="layui-input-block">
            <input id="categoryId" readonly="readonly" type="text" name="categoryId" value="" class="layui-input">
            <tip>id不可修改</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">分类名称</label>
        <div class="layui-input-block">
            <input id="categoryName" type="text" name="categoryName" lay-verify="required" lay-reqtext="分类名称不能为空" placeholder="分类名称" value="" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认修改</button>
        </div>
    </div>

</div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<!--<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>-->
<script>
    window.onload=function (e){
        console.log(e)
    }

    layui.use(['form'], function (obj) {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        // //给表单赋值
        // form.val("eidt", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
        //     "userName": "1756295440" // "name": "value"
        //     ,"userSex": "男"
        //     ,"userPhone": "123456789"
        //     ,"userPassword": "123456"
        //    , "userAccount":"123456"
        //     ,"userRole":1,
        //     "userBalance":100
        // });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("点击确认修改", {
                title: '确认提交'
            }, function () {
                $.post({
                    url:"/admin/category/update",
                    data:data.field,
                    success:function (data){

                        layer.msg(data.msg);

                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        // 关闭后刷新父页面
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    }
                })

            });

            return false;
        });

    });
</script>
</body>
</html>